package com.itheima.easy.controller;

import com.itheima.easy.base.AjaxResult;
import com.itheima.easy.dto.FloorDto;
import com.itheima.easy.service.FloorService;
import com.itheima.easy.vo.FloorVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/floor")
@Api(tags = "楼层管理")
public class FloorController extends BaseController {

    @Autowired
    private FloorService floorService;

    @PostMapping("/add")
    @ApiOperation(value = "添加楼层", notes = "传入楼层信息，返回添加结果")
    public AjaxResult addFloor(@RequestBody FloorDto floorDto) {
        floorService.addFloor(floorDto);
        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除楼层", notes = "根据楼层id删除指定楼层，返回删除结果")
    public AjaxResult deleteFloor(@PathVariable Long id) {
        floorService.deleteFloor(id);
        return AjaxResult.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新楼层", notes = "传入更新的楼层信息，返回更新结果")
    public AjaxResult updateFloor(@RequestBody FloorDto floorDto) {
        floorService.updateFloor(floorDto);
        return AjaxResult.success();
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取楼层", notes = "根据楼层id获取指定楼层，返回楼层信息")
    public AjaxResult<FloorVo> getFloor(@PathVariable Long id) {
        return AjaxResult.success(floorService.getFloor(id));
    }

    @GetMapping("/getAll")
    @ApiOperation(value = "获取所有楼层", notes = "无需参数，获取所有楼层，返回楼层信息列表")
    public AjaxResult<List<FloorVo>> getAllFloors() {
        return AjaxResult.success(floorService.getAllFloors());
    }
}
